public class class3 {
    import java.util.ArrayList;
import java.util.List;

    class School {
        private List<Department> departments;

        public School() {
            this.departments = new ArrayList<>();
        }

        public void addDepartment(Department department) {
            departments.add(department);
        }

        public List<Department> getDepartments() {
            return departments;
        }
    }

    class Department {
        private List<Instructor> instructors;
        private List<Subject> subjects;
        private String name;

        public Department(String name) {
            this.name = name;
            this.instructors = new ArrayList<>();
            this.subjects = new ArrayList<>();
        }

        public void addInstructor(Instructor instructor) {
            instructors.add(instructor);
        }

        public void addSubject(Subject subject) {
            subjects.add(subject);
        }

        public String getName() {
            return name;
        }

        public List<Instructor> getInstructors() {
            return instructors;
        }

        public List<Subject> getSubjects() {
            return subjects;
        }
    }

    class Instructor {
        private String name;
        private Department department;
        private List<Subject> subjects;

        public Instructor(String name, Department department) {
            this.name = name;
            this.department = department;
            this.subjects = new ArrayList<>();
        }

        public void addSubject(Subject subject) {
            if (subjects.size() < 3) {  // 教授最多3门课程
                subjects.add(subject);
            }
        }

        public String getName() {
            return name;
        }

        public Department getDepartment() {
            return department;
        }

        public List<Subject> getSubjects() {
            return subjects;
        }
    }

    class Subject {
        private String title;
        private List<Student> students;

        public Subject(String title) {
            this.title = title;
            this.students = new ArrayList<>();
        }

        public void enrollStudent(Student student) {
            if (students.size() < 50) {  // 假设每门课程最多50名学生
                students.add(student);
                student.addSubject(this); // 学生也记录所选课程
            }
        }

        public String getTitle() {
            return title;
        }

        public List<Student> getStudents() {
            return students;
        }
    }

    class Student {
        private String name;
        private List<Subject> subjects;

        public Student(String name) {
            this.name = name;
            this.subjects = new ArrayList<>();
        }

        public void addSubject(Subject subject) {
            if (subjects.size() < 5) {  // 每个学生最多参加5门课程
                subjects.add(subject);
            }
        }

        public String getName() {
            return name;
        }

        public List<Subject> getSubjects() {
            return subjects;
        }
    }
}
